#include "bullet.h"

Bullet::Bullet()
{
    //加载子弹图片
    m_Bullet.load(BULLET_PATH);

    m_Bullet = m_Bullet.scaled(50, 50);

    //子弹坐标
    //m_X = (GAME_WIDTH - m_Bullet.width())/2;
    m_X = GAME_WIDTH/2 - m_Bullet.width()/2;
    m_Y = GAME_HEIGHT;

    //子弹状态
    m_Free = true;

    //子弹速度
    m_Speed = BULLET_SPEED;

    //子弹边框
    m_Rect.setWidth(m_Bullet.width());
    m_Rect.setHeight(m_Bullet.height());

    m_Rect.moveTo(m_X, m_Y);

}

void Bullet::updatePosition()
{
    //空闲状态的子弹，不需要计算坐标
    if(m_Free)
    {
        return;
    }

    //子弹移动
    m_Y-=m_Speed;
    m_Rect.moveTo(m_X, m_Y);

    //子弹超出屏幕，从新设置状态
    if(m_Y<=-m_Rect.height())
    {
        m_Free = true;
    }
}
